<?php
Globals::requireClass('Controller');
Globals::requireModel('User');
Globals::requireTable('Recommendseek');
Globals::requireTable('Config');
class RecommendseekController extends Controller
{
    protected $Recommendseek;
    protected $ConfigTable;
	
	public static $defaultConfig = array(
		'viewEnabled'	=> true,
		'layoutEnabled'	=> true,
		'title'			=> null
	);
	
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->Recommendseek = new RecommendseekTable($config);
		$this->ConfigTable = new ConfigTable($config);
		dolog(json_encode($_GET));
	}
	
	public function recommendseeklistAction(){
	    $re = array(
	        'returncode' => '-1',
	        'recommendseektime' => '',
	        'defaulseek' => '',
	        'defaulseekturl' => '',
	        'seekurl' => '',
	        'sectionid' => '',
	        'sectiontitle' => '',
	        'sectioncontent' => array()
	    );
	    
	    $uid = $this->getParam('uid');
	    $token = $this->getParam('token');
	    $machine_type = $this->getParam('machine_type');
	    $usermodel = new UserModel($this->config);
	    $uid = $usermodel->getUserBase($uid, $token ,$machine_type);
	    if($uid < 1){
	        echo json_encode($re);
	        exit();
	    }
	    
	    $re['returncode'] = '0';
	    
	    $recommendseektime = $this->getParam('recommendseektime');
	    
	    $ctime = $this->ConfigTable->getRow(4);
	    if($recommendseektime < $ctime['value']){
	        $re['recommendseektime'] = $ctime['value'];
	        
	        $data5 = $this->ConfigTable->getRow(5);
	        $re['defaulseek'] = $data5['value'];
	        
	        $data6 = $this->ConfigTable->getRow(6);
	        $re['defaulseekturl'] = $data6['value'];
	        
	        $data7 = $this->ConfigTable->getRow(7);
	        $re['seekurl'] = $data7['value'];
	        
	        $re['sectionid'] = '1';
	        $re['sectiontitle'] = '热搜';
	        
	        $data = $this->Recommendseek->listAll();
	        foreach ($data as $v){
	            $tmp = array(
	                'contentname' => $v['name'],
	                'url' => $v['url']
	            );
	            
	            $re['sectioncontent'][] = $tmp;
	        }
	    }
	    
	    echo json_encode($re);
	    exit();
	}
	
	protected function out()
	{
		$this->layout->nav		= 'index';
		parent::out();
	}
}

Config::extend('RecommendseekController', 'Controller');
